package com.myprocessing.gui;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.myprocessing.box.Box;
import com.myprocessing.gui.util.Coord;
import com.myprocessing.gui.util.ProcessingObjectWrapper;

public class ScreenManager extends ProcessingObjectWrapper {

	private Map<String, Box> screenMap = new HashMap<String, Box>();
	private Box currentScreen;
	private Coord size; 

	public void changeScreen(Box newScreen){
		currentScreen.setActive(false);
		currentScreen = newScreen;
		currentScreen.setActive(true);
	}
	
	public void changeScreenByName(String newScreenStr){
		currentScreen.setActive(false);
		currentScreen = screenMap.get(newScreenStr);
		currentScreen.setActive(true);
	}
	
	public void activateBox(Box box){
		box.setActive(true);
	}
	
	public void activateBoxes(List<Box> boxes){
		for(Box box:  boxes){
			box.setActive(true);
		}
	}
	
	public void activateBoxAtPos(Box box, Coord coord){
		box.setPosition(coord);
		box.setActive(true);
	}
	
	public void deactivateBox(Box box){
		box.setActive(false);
	}
	
	public void deactivateBoxes(List<Box> boxes){
		for(Box box:  boxes){
			pApplet.println("deactivate: " +box.getName());
			box.setActive(false);
		}
	}
	
	public void onMousePress(){
		if(currentScreen != null){
			currentScreen.onMousePress();
		}
	}

	public void onMouseOver(){
		if(currentScreen != null){
			currentScreen.onMouseOver();
		}
	}

	public void onMouseEnter(){
		if(currentScreen != null){
			currentScreen.onMouseEnter();
		}
	}

	public void onMouseExit(){
		if(currentScreen != null){
			currentScreen.onMouseExit();
		}
	}

	public void onNotMouseOver(){
		if(currentScreen != null){
			currentScreen.onNotMouseOver();
		}
	}
	
	public void onkeyPressed(char key){
		if(currentScreen != null){
			currentScreen.onKeyPressed(key);
		}
	}
	
	public void init(){
		for(Box screen: screenMap.values()){
			screen.init();
		}
	}
	
	public void display(){
		pApplet.background(0);
		currentScreen.display();
	}

	public Map<String, Box> getScreenMap() {
		return screenMap;
	}

	public void setScreenMap(Map<String, Box> screenMap) {
		this.screenMap = screenMap;
	}

	public Box getScreen(String name){
		return screenMap.get(name);
	}
	
	public Box getCurrentScreen() {
		return currentScreen;
	}
	
	public void setCurrentScreen(Box currentScreen) {
		this.currentScreen = currentScreen;
	}

	public Coord getSize() {
		return size;
	}

	public void setSize(Coord size) {
		this.size = size;
	}
	
	public void println(String arg) {
		System.out.println(arg);
	}
	
}
